﻿using System;
using System.Collections.Generic;
using Tanmia.Basis.Core;
using Tanmia.Basis.Data;
using Tanmia.Basis.Data.NHibernate;

namespace Tanmia.Basis.Domain
{
    public class BaseDomain<TCore> : SecurityDomain<TCore>
        where TCore : BaseBusinessObject
    {
        public BaseDomain(ISessionManager sessionManager)
        {
            this.SessionManager = sessionManager;
            this.Repository = new Repository<TCore>(SessionManager);
        }

        public override void Save(TCore entity)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");

            base.Save(entity);
        }

        public override void Delete(TCore entity)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");

            base.Delete(entity);
        }

        public override TCore Get(int entityID)
        {
            if (entityID == 0)
                throw new ArgumentException("entityID");

            return base.Get(entityID);
        }

        public override IList<TCore> Gets(Specification<TCore> specs)
        {
            if (specs == null)
                throw new ArgumentNullException("specs");

            return base.Gets(specs);
        }

        public override IList<TCore> Gets(System.Linq.Expressions.Expression<Func<TCore, bool>> satisfy)
        {
            if (satisfy == null)
                throw new ArgumentNullException("satisfy");

            return base.Gets(satisfy);
        }
    }
}
